'''
Author: your name
Date: 2021-03-23 09:41:58
LastEditTime: 2021-11-06 20:53:06
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: /tinyms/tinyms-api/app.py
'''
#coding=UTF-8
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_httpauth import HTTPBasicAuth
from flask_cors import CORS
# import werkzeug
# werkzeug.cached_property = werkzeug.utils.cached_property


import logging
import config

app = Flask(__name__)
CORS(app)
#读取config.py中的配置
app.config.from_object('config')

#jsonify()输出的json 支持中文
app.config['JSON_AS_ASCII'] = False
db = SQLAlchemy(app)
auth = HTTPBasicAuth()


from apps.auth.main import main_login
from apps.auth.menu import auth_menu
from apps.auth.user import auth_user
from apps.auth.role import auth_role
from apps.auth.census import auth_census
from apps.auth.organ import auth_organ
from apps.auth.notice import auth_notice
from apps.auth.dict import auth_dict


from apps.cms.article import cms_article
from apps.cms.site import cms_site
from apps.cms.link import cms_link
from apps.cms.channel import cms_channel
from apps.cms.articlechannel import cms_articlechannel


#权限控制
# 登录模块
app.register_blueprint(main_login,url_prefix='/')
#菜单管理
app.register_blueprint(auth_menu,url_prefix='/auth/menu')
#角色管理
app.register_blueprint(auth_role,url_prefix='/auth/role')
#用户管理模块
app.register_blueprint(auth_user, url_prefix='/auth/user')
#权限系统统计相关
app.register_blueprint(auth_census, url_prefix='/auth/census')
#组织机构模块
app.register_blueprint(auth_organ, url_prefix='/auth/organ')
#通知模块
app.register_blueprint(auth_notice, url_prefix='/auth/notice')
#字典管理模块
app.register_blueprint(auth_dict, url_prefix='/auth/dict')

#内容发布
# 链接管理模块
app.register_blueprint(cms_link, url_prefix='/cms/link')
#文章管理模块
app.register_blueprint(cms_article, url_prefix='/cms/article')
#站点管理模块
app.register_blueprint(cms_site, url_prefix='/cms/site')
#栏目管理模块
app.register_blueprint(cms_channel, url_prefix='/cms/channel')
#文章栏目关联模块
app.register_blueprint(cms_articlechannel, url_prefix='/cms/articlechannel')

if __name__ == '__main__':
    app.debug = True
    #日志输出
    handler = logging.FileHandler('flask.log')
    handler.setLevel(logging.DEBUG)
    logging_format = logging.Formatter(
        '%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s')
    handler.setFormatter(logging_format)
    app.logger.addHandler(handler)
    app.run()
    # app.run(debug=True)
